#pragma once
#include "StdAfx.h"


/*
	The singleton class that manages the content that is used by the application.
	The content is first loaded as file names using a config file, and then, when OpenGL has been initialized, it's fully loaded from the hard drive.
	The initialize content should be called at least once. Any subsequent calls will have no effect.

	It also contains the Log vector. Upon destructor call, it will be dumped into the Log.txt.

	Arseni Natapov, 1/11/2011
*/
class ContentManager
{
public:
	ContentManager(void);
	~ContentManager(void);
	
	//individual load function
	void Load(GameResource*);
	//accessors
	//get an uncasted smart pointer
	//castable via macros
	sptr<GameResource> Get(string);
	//add entry to log function
	void AddToLog(string);
	void SaveLog();
private:
	//various path strings
	string	ConfigPath, 
			TexturesFolder, 
			MeshesFolder, 
			ShadersFolder, 
			ModelsFolder, 
			MaterialsFolder;
	//the log of the system
	std::vector<string> Log;
	Vector<sptr<GameResource>> Resources;
	friend class SingletonManager;
	//load initial content function
	void LoadContent();
	//initialize the content that has been loaded
	void InitContent();
	//load resources of type T from the block
	template<typename T>
	void LoadBlock(string block_name, string folder_path)
	{
		//grab the config file with the list of resources to load
		Reader reader(ConfigPath);
		//read the block into a vector
		BBVector<sptr<Binding>> bindings=reader.GetBindings(block_name);
		//add resources of given type and with fetched Name/Path pairs
		for(unsigned int i=0;i<bindings.size();i++)
		{
			GameResourceDesc grdesc;
			grdesc.Name=bindings[i]->Name;
			grdesc.FileName=folder_path<<bindings[i]->Aux;
			Resources.push_back(sptr<T>(new T(grdesc)));
		}
	}
};
